#include "../../source/common/net.hpp"
#include "../../source/server/rpc_server.hpp"

#include <memory>
#include <functional>

void ADD(const Json::Value &params, Json::Value &result)
{
    int num1 = params["num1"].asInt();
    int num2 = params["num2"].asInt();
    result = num1 + num2;
}

// server->dispatcher->router->method
int main()
{
    JsonMuduoRPC::server::RPCServer::ptr server =
        std::make_shared<JsonMuduoRPC::server::RPCServer>(JsonMuduoRPC::Address("127.0.0.1", 8080));

    // 0. 构建服务描述
    JsonMuduoRPC::server::ServiceDescribeFactory service_factory;
    service_factory.setParamsDescribe("num1", JsonMuduoRPC::server::VType::INTEGRAL);
    service_factory.setParamsDescribe("num2", JsonMuduoRPC::server::VType::INTEGRAL);
    service_factory.setResultType(JsonMuduoRPC::server::VType::INTEGRAL);
    service_factory.setServiceCallBack(ADD);
    service_factory.setServiceName("ADD");

    server->registryMethod(service_factory.bulid());

    server->start();

    return 0;
}